// pages/promise/product/product.js
const http = require("../../../utils/request");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    datas: {},
    isopen: true,
    showWarn: false,
    url: "",
    test: 2,//是否已送达
    display: true,
    type: {
      dispatchCode: "运输批次",
      cultivationCode: "养殖批次",
      count: "分拨数量（只）",
      arrivalTime:"到达时间",
      destination: "货品去向",
      driver: "司机",
      remark: "备注",
      pictrue: "照片"
    }
  },
  copy(e) {
    let datas = String(e.currentTarget.dataset.data)
    if(datas === 'undefined' || datas === '') {
      datas = null
    }
    wx.setClipboardData({
      data: datas,
      success: (res) => {
        wx.getClipboardData({
          success: (option) => {
            wx.showToast({
              title: '复制成功',
            })
          },
          fail: (res) => {
          },
          complete: (res) => {},
        })
      },
      fail: (res) => {
        wx.showToast({
          title: '复制失败',
          icon: 'error',
        })
      },
      complete: (res) => {},
    })
  }, 
  deleteshow() {
    let is = !this.data.isdelete
    this.setData({
      isdelete: is,
    })
  },
  open() {
    let val = !this.data.isopen;
    this.setData({
      isopen: val,
    })
  },
  edit(){
    let app = getApp();
    app.globalData.operation = 0;
    console.log(this.data.datas);
    app.globalData.trans_data = this.data.datas;
    wx.navigateTo({
      url: '../change/change',
    })
  },
  closeDialog() {
    this.setData({
      showWarn: false
    })
  },
  destory() {
    this.setData({
      showWarn: true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let dataer = getApp().globalData.promise_data;
    http.getRequest('/admin/dispatch?code='+dataer.dispatchCode,{},res=>{
      this.setData({
        datas: res.data.data,
        display:false
      })
      http.postRequestBody('/admin/dispatch/'+this.data.datas.dispatchCode+'/qrCode',{},res=>{
        console.log(1,res);
        if(res.data.success){
          this.setData({
            url: res.data.data,
          })
        }
      },err=>{})
    },err=>{})
  },
  arrival(){
    this.setData({
      display: true,
    })
    http.putRequest('/admin/dispatch/'+ this.data.datas.dispatchCode+'/arrival',{},res=>{
        this.onLoad();
    },err=>{})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.onLoad();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})